home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1989 / 01 / msdosa.asc < prev    next >
Text File  |  1989-01-02  |  5KB  |  273 lines

  1. _MS-DOS ASSEMBLERS COMPARED_
  2.  
  3. by Michael Schmit
  4.  
  5. [FIGURE 1]
  6.  
  7.  
  8. problem:
  9.  
  10.             ...
  11.             cmp  ax, 1
  12.             je   near_label
  13.             ... > 128 bytes of code
  14. near_label:
  15.             ...
  16.  
  17.  
  18. correction:
  19.  
  20.             ...
  21.             cmp  ax, 1
  22.             jne  $ + 3
  23.             jmp  near_label
  24.             ... > 128 bytes of code
  25. near_label:
  26.             ...
  27.  
  28. [FIGURE 2]
  29.  
  30.  
  31.  
  32. Old method (MASM 5.0 and before):
  33.  
  34.  
  35.          Public _sample_func
  36.          _sample_func proc near
  37.          push   bp
  38.          mov    bp, sp
  39.          push   bx
  40.          push   cx
  41.          push   dx
  42.  
  43.          mov    bx, [bp+4]    ; get ptr to var1
  44.          ...
  45.  
  46.          pop    dx
  47.          pop    cx
  48.          pop    bx
  49.          pop    bp
  50.          ret
  51.          _sample_func endp
  52.  
  53.  
  54. New Method:
  55.  
  56.          .model small, C
  57.          .code
  58.  
  59.          sample_func proc near USES BX CX DX, var1:PTR
  60.  
  61.          mov    bx, var1      ; get ptr to var1
  62.          ...
  63.  
  64.          ret
  65.          sample_func endp
  66.  
  67.  
  68.  
  69. [FIGURE 3]
  70.  
  71.  
  72.                 test description              MASM     TASM    OPTASM
  73.  
  74.     test 1 (15 files, 600K total)               85       50       35
  75.     test 2 (6 files, 100K each)                 80       40       26
  76.     test 3 (test 1 with wildcards/make)         85       34       24
  77.     test 4 (test 2 with wildcards/make)         80       32       22
  78.  
  79.  
  80.     Notes:
  81.           1) Times are in seconds
  82.           2) All tests on 10 MHz AT clone,
  83.              zero wait states, Seagate
  84.              ST-251 hard disk, no cache
  85.  
  86. There were 4 test cases run, as described in the article.
  87. Each test consists of just 3 data points, one for each of the assemblers.
  88.  
  89.  
  90.  
  91.  
  92. [FIGURE 4]
  93.  
  94.  
  95. ; MASM example
  96.  
  97. @@:
  98.     inc   ax
  99.     cmp   ax, bx
  100.     je    @f
  101.     loop  @b
  102. @@:
  103.     ret
  104.  
  105.  
  106.  
  107. ; TASM example
  108.  
  109. @@loop:
  110.     inc   ax
  111.     cmp   ax, bx
  112.     je    @@exit
  113.     loop  @@loop
  114. @@exit:
  115.     ret
  116.  
  117. ; OPTASM example
  118.  
  119. #1:
  120.     inc   ax
  121.     cmp   ax, bx
  122.     je    #2
  123.     loop  #1
  124. #2:
  125.     ret
  126.  
  127.  
  128.  
  129.  
  130. [FIGURE 5]
  131.  
  132.  
  133.  
  134. title  MASM mode example program   ; comment in title
  135. .model small
  136.  
  137. stdin   = 0
  138. stdout  = 1
  139. buf_len = 128
  140.  
  141. dosint MACRO function      ; macro to invoke a DOS interrupt 21h function
  142.   mov ah, function
  143.   int 21h
  144. ENDM
  145.  
  146. .code
  147.  
  148. main PROC
  149.  
  150.    mov   ax, @data           ; load data segment
  151.    mov   ds, ax
  152.    mov   es, ax
  153.    mov   dx, OFFSET inbuf    ; dest for input
  154.    mov   bx, stdin           ; source of input
  155.    mov   cx, buf_len         ; len for input
  156.    dosint 3fh                ; read file
  157.    cmp   ax, 2
  158.    jle   fin
  159.    mov   bx, ax
  160.    mov   inbuf[bx-2], 0      ; null at end (remove CR LF)
  161.    mov   cx, ax              ; len for example
  162.    sub   cx, 2               ; removes CR LF
  163.    call  lower_line
  164.    mov   dx, OFFSET outbuf   ; source of output
  165.    mov   bx, stdout          ; dest for output
  166.    dosint 40h                ; write file
  167. fin:
  168.    dosint 4ch                ; exit to DOS
  169.  
  170. main ENDP
  171.  
  172. lower_line PROC near
  173.  
  174.    push  cx
  175.    mov   si, OFFSET inbuf
  176.    xor   di, di              ; for example no STOS for DI
  177.    cld
  178. loop1:
  179.    lodsb                     ; read a char
  180.    or    al, 20h             ; convert to lower case
  181.    mov   outbuf[di], al      ; store in outbuf
  182.    inc   di
  183.    loop  loop1               ; loop til end of string
  184.    pop   cx
  185.    ret
  186.  
  187. lower_line ENDP
  188.  
  189. .data
  190.  
  191. inbuf  DB buf_len DUP(?)
  192. outbuf DB buf_len DUP(?)
  193.  
  194. stk SEGMENT STACK            ; reserve space for stack
  195.  db 100 dup(0)               ; using old segment method
  196. stk ENDS
  197.  
  198. END main                     ; specify starting address
  199.  
  200. ----------------------------------------
  201.  
  202. IDEAL
  203. %title  "TASM IDEAL mode example program"   ; comment not in title
  204.                              ; all directives affecting listing
  205.                              ; file begin with a percent sign (%)
  206.  
  207. model small                  ; no periods in IDEAL directives
  208.  
  209. stdin   = 0
  210. stdout  = 1
  211. buf_len = 128
  212.  
  213. MACRO dosint function        ; label and MACRO reversed
  214.   mov ah, function
  215.   int 21h
  216. ENDM
  217.  
  218. codeseg                      ; segmentation directive renamed
  219.  
  220. PROC main                    ; label and PROC reversed
  221.  
  222.    mov   ax, @data
  223.    mov   ds, ax
  224.    mov   es, ax
  225.    mov   dx, OFFSET inbuf
  226.    mov   bx, stdin
  227.    mov   cx, buf_len
  228.    dosint 3fh
  229.    cmp   ax, 2
  230.    jle   fin
  231.    mov   bx, ax
  232.    mov   [bx+inbuf-2], 0     ; memory reference must be in []
  233.    mov   cx, ax
  234.    sub   cx, 2
  235.    call  lower_line
  236.    mov   dx, OFFSET outbuf
  237.    mov   bx, stdout
  238.    dosint 40h
  239. fin:
  240.    dosint 4ch
  241.  
  242. ENDP main                    ; label and ENDP reversed
  243.  
  244. PROC lower_line near
  245.  
  246.    push  cx
  247.    mov   si, OFFSET inbuf
  248.    xor   di, di
  249.    cld
  250. @@loop1:
  251.    lodsb
  252.    or    al, 20h
  253.    mov   [di+outbuf], al     ; memory reference in []
  254.    inc   di
  255.    loop  @@loop1             ; local labels available
  256.    pop   cx
  257.    ret
  258.  
  259. ENDP                         ; matching PROC name optional
  260.  
  261. dataseg                      ; segmentation directive renamed
  262.  
  263. inbuf  DB buf_len DUP(?)
  264. outbuf DB buf_len DUP(?)
  265.  
  266. SEGMENT stk STACK            ; label and SEGMENT reversed
  267.  db 100 dup(0)
  268. ENDS                         ; matching SEG name optional
  269.  
  270. END main
  271.  
  272.  
  273.